#if 0
	shc Version 4.0.3, Generic Shell Script Compiler
	GNU GPL Version 3 Md Jahidul Hamid <jahidulhamid@yahoo.com>

	shc -r -v -f clean_location.sh 
#endif

static  char data [] = 
#define      pswd_z	256
#define      pswd	((&data[33]))
	"\020\270\360\356\263\145\261\322\360\113\037\246\357\203\277\220"
	"\354\055\216\131\300\053\115\037\054\276\315\070\302\117\376\323"
	"\007\027\166\177\035\035\261\131\217\275\352\044\147\257\123\261"
	"\357\130\223\075\177\211\343\202\141\223\332\037\147\132\041\104"
	"\162\227\303\220\265\165\351\104\062\324\151\231\203\274\113\163"
	"\025\337\261\225\150\224\030\312\047\362\351\217\115\012\323\277"
	"\242\227\120\127\014\071\234\077\015\006\331\221\303\044\005\331"
	"\003\266\156\154\113\206\066\163\171\040\003\306\052\327\206\315"
	"\156\326\045\173\020\302\273\036\310\224\257\214\271\265\145\274"
	"\154\324\051\267\133\140\053\324\200\056\233\252\005\041\170\164"
	"\367\235\360\010\137\254\046\050\100\326\265\371\213\033\266\367"
	"\357\340\257\113\100\332\040\300\011\273\153\016\335\343\203\325"
	"\201\164\335\341\040\003\012\140\331\277\132\145\332\021\134\312"
	"\362\014\026\062\346\066\363\357\362\137\376\320\103\202\245\304"
	"\366\203\246\026\206\260\167\140\157\322\305\112\344\042\025\327"
	"\057\053\011\025\142\375\005\125\134\004\045\237\206\313\144\175"
	"\116\012\223\325\272\013\065\052\336\373\165\302\036\212\231\115"
	"\266\243\143\030\241\151\156\375\155\223\235\363\136\001\160\255"
	"\013\356\301\273\124\163\215\104\276\255\353\256\060\252\076\034"
	"\327\314\166\230\370\303\270\044\201\205\134\104\325\132\027\335"
	"\111\331\230\236\115\046\342\014\324\315\272\005\170\371\041\117"
	"\306\227\350"
#define      opts_z	1
#define      opts	((&data[339]))
	"\047"
#define      tst2_z	19
#define      tst2	((&data[344]))
	"\077\041\374\232\332\340\076\351\062\327\236\123\257\137\124\115"
	"\055\257\044\112\133\073\226"
#define      shll_z	10
#define      shll	((&data[365]))
	"\023\162\040\217\057\310\065\271\101\161\262\355\202\140"
#define      chk1_z	22
#define      chk1	((&data[379]))
	"\155\063\336\337\302\341\056\357\217\110\274\371\302\034\363\212"
	"\236\005\115\165\024\362\052\011\047\162"
#define      rlax_z	1
#define      rlax	((&data[403]))
	"\331"
#define      chk2_z	19
#define      chk2	((&data[408]))
	"\344\245\207\205\012\306\256\031\045\030\176\143\057\047\161\315"
	"\346\234\212\007\004\235\254"
#define      msg2_z	19
#define      msg2	((&data[428]))
	"\310\255\163\276\142\040\205\175\371\056\176\276\332\056\126\061"
	"\221\064\005\377\205\247\143"
#define      text_z	1785
#define      text	((&data[675]))
	"\322\363\312\063\214\060\237\371\143\307\154\017\350\001\013\320"
	"\055\357\166\264\164\377\031\040\307\237\307\053\136\110\163\060"
	"\073\076\143\310\156\003\302\322\313\056\342\264\057\355\204\135"
	"\334\372\022\121\371\053\161\301\312\071\354\051\201\140\132\275"
	"\236\276\206\015\301\110\337\215\167\301\101\247\257\306\004\214"
	"\300\026\335\272\102\117\173\015\210\150\066\012\310\220\310\147"
	"\116\116\164\020\226\124\235\016\026\337\265\305\245\271\122\146"
	"\320\057\040\022\177\234\037\007\005\126\021\315\346\331\065\065"
	"\050\252\105\276\376\343\315\024\302\202\332\150\074\055\316\014"
	"\134\357\037\333\213\077\343\220\225\364\136\174\316\224\261\366"
	"\076\366\265\074\331\202\121\234\005\054\004\101\131\323\116\266"
	"\302\156\222\116\255\166\337\103\152\075\277\071\322\160\057\020"
	"\147\345\115\100\150\237\335\155\313\341\257\045\264\375\334\167"
	"\154\157\305\031\345\244\135\117\342\034\211\264\215\271\305\364"
	"\236\274\110\035\320\273\203\100\055\023\071\131\022\305\156\035"
	"\352\146\226\161\260\037\325\313\027\052\056\357\133\274\077\360"
	"\151\312\257\313\211\074\275\221\173\014\343\242\362\105\056\023"
	"\022\331\314\000\030\157\046\172\121\106\324\071\223\142\253\122"
	"\062\010\221\124\125\253\134\264\013\127\206\274\311\322\163\354"
	"\355\254\331\367\175\313\040\112\070\030\316\275\063\147\332\303"
	"\111\374\112\340\346\272\250\117\322\137\351\161\337\175\102\302"
	"\347\163\140\064\357\017\372\340\025\135\307\075\203\204\300\324"
	"\312\345\016\104\151\157\356\034\346\153\267\222\311\207\235\171"
	"\214\202\275\143\222\236\216\074\171\132\270\275\300\322\340\250"
	"\337\324\245\003\364\076\021\165\341\240\027\113\374\163\067\250"
	"\134\272\146\124\065\026\136\230\244\324\145\150\231\124\106\021"
	"\035\125\302\353\145\257\362\224\040\146\320\264\143\267\117\316"
	"\262\222\075\241\172\327\310\005\136\027\267\224\267\347\301\345"
	"\061\203\015\252\222\110\215\000\364\272\014\265\262\015\073\375"
	"\350\143\364\003\162\064\013\050\050\006\150\160\346\203\032\062"
	"\244\354\102\052\161\311\043\163\122\234\154\110\135\232\360\036"
	"\061\306\311\334\127\016\312\371\264\165\071\210\313\073\041\034"
	"\216\165\306\075\176\077\146\123\253\155\107\216\350\372\003\307"
	"\016\341\247\167\373\233\324\012\262\327\201\005\250\345\001\162"
	"\332\047\235\224\255\245\322\211\167\316\050\077\320\076\354\005"
	"\120\065\372\076\376\170\214\075\271\224\040\254\273\116\365\231"
	"\254\156\036\141\114\214\131\174\011\153\356\365\175\041\225\321"
	"\216\225\321\000\161\371\204\123\064\176\315\216\327\021\120\273"
	"\373\131\226\336\070\115\177\052\271\356\137\227\242\236\066\101"
	"\007\300\265\136\270\370\233\041\324\366\140\077\170\150\115\340"
	"\241\043\115\374\145\343\225\213\045\033\266\375\143\343\241\325"
	"\264\233\240\115\065\272\327\132\174\163\230\176\017\171\121\050"
	"\014\051\202\136\126\263\303\026\174\272\133\372\314\331\072\041"
	"\010\147\155\350\167\211\313\036\370\220\167\112\125\236\002\047"
	"\262\052\371\203\211\133\003\017\340\241\250\277\026\352\212\024"
	"\261\115\007\004\030\300\234\331\033\211\240\030\032\267\024\154"
	"\226\125\303\234\345\346\321\131\373\250\031\114\377\367\036\075"
	"\050\001\241\267\327\176\354\153\222\134\327\211\376\364\344\317"
	"\131\367\150\231\245\120\327\302\013\001\116\115\274\342\060\017"
	"\260\326\247\346\240\016\211\241\376\241\340\016\005\275\064\307"
	"\301\373\206\350\126\226\065\077\265\252\146\023\233\125\362\110"
	"\166\307\031\261\225\165\364\250\316\271\267\007\020\245\350\114"
	"\341\132\126\034\343\306\164\077\365\164\213\261\016\133\170\002"
	"\273\144\274\313\155\126\122\151\306\374\262\237\273\361\044\146"
	"\317\007\233\352\116\040\075\023\334\135\167\061\041\350\143\305"
	"\231\362\162\355\156\170\246\232\354\141\140\204\276\244\340\263"
	"\367\247\031\140\266\246\112\146\007\105\201\071\307\321\134\277"
	"\340\227\156\072\105\347\164\114\070\322\262\347\017\022\246\051"
	"\332\046\225\101\354\055\130\066\110\266\370\020\302\330\351\234"
	"\221\054\366\254\250\367\113\113\076\144\204\240\130\357\001\153"
	"\156\176\250\020\031\073\353\371\045\017\070\373\066\357\020\141"
	"\375\327\353\312\125\374\067\306\250\055\315\106\056\024\063\275"
	"\262\222\025\267\316\272\046\011\273\033\311\055\211\203\164\373"
	"\136\064\153\271\343\012\215\162\050\242\000\366\351\047\254\205"
	"\001\337\006\245\052\365\345\370\310\243\127\111\256\025\272\124"
	"\353\372\057\056\020\006\312\167\043\014\102\225\274\032\007\165"
	"\335\320\077\003\135\110\202\173\360\242\300\253\353\306\261\301"
	"\116\327\337\125\127\314\115\065\377\206\130\247\251\321\142\363"
	"\367\335\117\220\144\151\076\031\253\103\024\262\022\176\052\347"
	"\072\376\126\245\037\345\263\067\013\107\232\230\054\012\107\055"
	"\361\075\153\155\073\036\032\036\116\322\147\054\367\266\113\227"
	"\226\276\104\317\164\015\260\055\107\356\217\307\246\161\047\265"
	"\126\111\126\162\226\163\061\176\330\313\307\146\243\262\001\161"
	"\014\335\016\325\302\326\264\275\023\172\166\173\144\306\003\211"
	"\175\103\067\051\134\145\144\032\161\254\171\222\021\374\161\062"
	"\361\257\016\233\247\040\235\027\251\200\215\201\052\004\053\170"
	"\323\326\321\046\252\201\336\236\121\324\156\305\045\304\046\023"
	"\302\000\132\204\310\070\356\257\013\204\046\116\263\043\113\115"
	"\252\106\227\156\262\136\270\370\116\113\336\244\167\347\050\155"
	"\361\255\340\052\367\123\254\363\221\151\007\171\064\102\053\354"
	"\247\111\270\101\332\201\364\256\360\365\146\134\072\307\203\171"
	"\342\105\370\046\021\360\241\150\135\054\016\007\232\150\240\205"
	"\021\063\362\263\253\100\211\020\371\205\127\146\133\000\321\371"
	"\332\157\342\273\225\326\076\004\025\346\366\162\117\324\316\337"
	"\363\032\151\217\112\206\173\302\352\062\244\264\226\106\203\023"
	"\011\204\363\141\014\136\271\352\346\107\165\311\347\257\134\360"
	"\356\112\345\031\376\204\362\352\101\220\152\315\112\202\311\300"
	"\070\174\073\231\341\105\014\275\201\027\277\067\352\372\162\267"
	"\341\110\140\057\247\252\107\253\076\114\003\123\112\067\051\235"
	"\041\351\356\343\176\027\003\321\015\017\221\164\033\015\127\317"
	"\140\060\006\144\065\215\356\213\046\065\270\230\161\004\207\075"
	"\374\202\320\073\206\240\364\256\352\037\143\222\134\234\137\065"
	"\266\053\005\300\033\266\345\006\130\105\324\030\060\070\013\310"
	"\154\370\322\340\000\031\071\225\055\143\237\333\301\042\364\053"
	"\157\121\364\123\052\243\125\046\144\001\341\263\247\103\067\154"
	"\061\015\140\317\336\115\051\370\374\361\254\310\243\267\117\014"
	"\367\302\153\143\112\115\136\145\153\204\331\327\202\172\366\332"
	"\155\111\101\041\011\267\353\014\045\262\065\204\355\116\277\074"
	"\003\252\236\242\011\166\203\074\145\217\037\014\123\356\264\242"
	"\020\224\355\372\076\304\001\154\371\076\305\116\021\324\375\370"
	"\360\103\311\076\265\042\206\135\141\366\145\237\303\133\041\106"
	"\244\035\213\234\166\207\220\153\131\000\232\367\045\305\220\172"
	"\260\157\377\253\272\250\363\325\013\341\236\325\007\216\071\003"
	"\161\330\372\360\024\171\121\107\365\171\022\043\004\021\013\241"
	"\242\324\346\273\222\122\322\030\324\367\270\076\361\257\027\046"
	"\245\253\233\207\112\155\260\375\076\045\021\167\212\104\065\350"
	"\107\150\335\273\140\033\005\266\133\316\253\161\021\351\227\324"
	"\215\161\020\371\333\170\325\041\325\155\077\073\146\053\201\172"
	"\251\176\324\156\143\063\014\261\207\344\050\016\334\205\147\220"
	"\113\163\313\336\243\047\172\234\201\341\105\234\110\253\015\123"
	"\025\160\075\111\212\242\260\312\361\022\042\305\250\336\346\310"
	"\345\023\226\272\326\016\275\020\240\013\215\337\154\035\045\312"
	"\212\077\367\372\024\364\270\107\115\267\053\242\020\013\367\325"
	"\112\352\107\010\207\375\017\102\046\313\375\020\373\005\200\307"
	"\331\261\007\330\217\200\202\215\225\237\023\137\015\064\031\112"
	"\043\136\365\153\113\360\070\303\121\265\176\213\051\203\211\212"
	"\072\261\202\011\233\301\160\334\100\233\110\214\256\013\060\253"
	"\337\222\114\064\167\044\151\253\306\256\274\105\354\243\146\306"
	"\122\012\014\245\004\377\307\013\315\004\124\154\123\007\122\066"
	"\120\226\363\316\251\012\060\244\111\372\050\376\250\244\223\034"
	"\225\341\207\343\307\232\007\231\350\340\011\154\230\106\275\332"
	"\350\363\062\333\035\372\206\173\230\160\216\223\226\176\155\305"
	"\005\325\337\245\264\374\023\121\060\055\045\265\206\255\344\022"
	"\103\072\272\040\044\170\152\322\046\052\142\225\035\310\117\201"
	"\047\257\367\370\265\323\360\303\370\304\357\075\315\141\135\311"
	"\156\061\211\217\336\206\056\040\336\263\022\065\007\261\022\164"
	"\175\364\044\243\251\041\177\040\216\356\346\247\323\213\005\043"
	"\156\041\254\043\257\146\350\243\004\373\331\013\255\353\200\052"
	"\340\244\316\211\306\115\252\124\074\221\374\020\035\001\064\213"
	"\043\340\256\322\107\227\165\113\222\117\127\077\072\330\151\033"
	"\174\070\245\103\205\120\227\302\341\224\323\377\225\007\212\270"
	"\350\071\213\057\320\000\172\142\117\322\241\212\252\013\246\047"
	"\103\113\152\311\234\001\214\176\225\137\175\053\146\010\344\116"
	"\101\157\175\021\160\370\164"
#define      msg1_z	65
#define      msg1	((&data[2598]))
	"\112\165\041\361\234\145\074\006\057\331\010\274\127\222\064\273"
	"\306\141\115\351\027\065\363\124\074\027\166\314\250\233\367\177"
	"\267\233\103\003\231\027\202\241\145\055\004\004\262\132\257\000"
	"\124\353\116\130\070\212\104\210\001\372\350\364\007\306\343\121"
	"\245\076\003\160\326\160\040\345\113\262\072\110\176\315\236"
#define      date_z	1
#define      date	((&data[2664]))
	"\005"
#define      tst1_z	22
#define      tst1	((&data[2670]))
	"\320\035\034\116\057\104\176\320\331\165\024\264\027\143\374\037"
	"\216\367\357\333\252\252\363\311\356\271\040\214\106\243\114"
#define      inlo_z	3
#define      inlo	((&data[2696]))
	"\145\066\326"
#define      xecc_z	15
#define      xecc	((&data[2702]))
	"\044\101\305\126\222\073\241\247\230\057\371\024\240\355\125\241"
	"\313\304\052\161"
#define      lsto_z	1
#define      lsto	((&data[2719]))
	"\306"/* End of data[] */;
#define      hide_z	4096
#define SETUID 0	/* Define as 1 to call setuid(0) at start of script */
#define DEBUGEXEC	0	/* Define as 1 to debug execvp calls */
#define TRACEABLE	1	/* Define as 1 to enable ptrace the executable */
#define HARDENING	0	/* Define as 1 to disable ptrace/dump the executable */
#define BUSYBOXON	0	/* Define as 1 to enable work with busybox */

#if HARDENING
static const char * shc_x[] = {
"/*",
" * Copyright 2019 - Intika <intika@librefox.org>",
" * Replace ******** with secret read from fd 21",
" * Also change arguments location of sub commands (sh script commands)",
" * gcc -Wall -fpic -shared -o shc_secret.so shc_secret.c -ldl",
" */",
"",
"#define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */",
"#define PLACEHOLDER \"********\"",
"#include <dlfcn.h>",
"#include <stdlib.h>",
"#include <string.h>",
"#include <unistd.h>",
"#include <stdio.h>",
"#include <signal.h>",
"",
"static char secret[128000]; //max size",
"typedef int (*pfi)(int, char **, char **);",
"static pfi real_main;",
"",
"// copy argv to new location",
"char **copyargs(int argc, char** argv){",
"    char **newargv = malloc((argc+1)*sizeof(*argv));",
"    char *from,*to;",
"    int i,len;",
"",
"    for(i = 0; i<argc; i++){",
"        from = argv[i];",
"        len = strlen(from)+1;",
"        to = malloc(len);",
"        memcpy(to,from,len);",
"        // zap old argv space",
"        memset(from,'\\0',len);",
"        newargv[i] = to;",
"        argv[i] = 0;",
"    }",
"    newargv[argc] = 0;",
"    return newargv;",
"}",
"",
"static int mymain(int argc, char** argv, char** env) {",
"    //fprintf(stderr, \"Inject main argc = %d\\n\", argc);",
"    return real_main(argc, copyargs(argc,argv), env);",
"}",
"",
"int __libc_start_main(int (*main) (int, char**, char**),",
"                      int argc,",
"                      char **argv,",
"                      void (*init) (void),",
"                      void (*fini)(void),",
"                      void (*rtld_fini)(void),",
"                      void (*stack_end)){",
"    static int (*real___libc_start_main)() = NULL;",
"    int n;",
"",
"    if (!real___libc_start_main) {",
"        real___libc_start_main = dlsym(RTLD_NEXT, \"__libc_start_main\");",
"        if (!real___libc_start_main) abort();",
"    }",
"",
"    n = read(21, secret, sizeof(secret));",
"    if (n > 0) {",
"      int i;",
"",
"    if (secret[n - 1] == '\\n') secret[--n] = '\\0';",
"    for (i = 1; i < argc; i++)",
"        if (strcmp(argv[i], PLACEHOLDER) == 0)",
"          argv[i] = secret;",
"    }",
"",
"    real_main = main;",
"",
"    return real___libc_start_main(mymain, argc, argv, init, fini, rtld_fini, stack_end);",
"}",
"",
0};
#endif /* HARDENING */

/* rtc.c */

#include <sys/stat.h>
#include <sys/types.h>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

/* 'Alleged RC4' */

static unsigned char stte[256], indx, jndx, kndx;

/*
 * Reset arc4 stte. 
 */
void stte_0(void)
{
	indx = jndx = kndx = 0;
	do {
		stte[indx] = indx;
	} while (++indx);
}

/*
 * Set key. Can be used more than once. 
 */
void key(void * str, int len)
{
	unsigned char tmp, * ptr = (unsigned char *)str;
	while (len > 0) {
		do {
			tmp = stte[indx];
			kndx += tmp;
			kndx += ptr[(int)indx % len];
			stte[indx] = stte[kndx];
			stte[kndx] = tmp;
		} while (++indx);
		ptr += 256;
		len -= 256;
	}
}

/*
 * Crypt data. 
 */
void arc4(void * str, int len)
{
	unsigned char tmp, * ptr = (unsigned char *)str;
	while (len > 0) {
		indx++;
		tmp = stte[indx];
		jndx += tmp;
		stte[indx] = stte[jndx];
		stte[jndx] = tmp;
		tmp += stte[indx];
		*ptr ^= stte[tmp];
		ptr++;
		len--;
	}
}

/* End of ARC4 */

#if HARDENING

#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/prctl.h>
#define PR_SET_PTRACER 0x59616d61

/* Seccomp Sandboxing Init */
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <sys/socket.h>

#include <linux/filter.h>
#include <linux/seccomp.h>
#include <linux/audit.h>

#define ArchField offsetof(struct seccomp_data, arch)

#define Allow(syscall) \
    BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SYS_##syscall, 0, 1), \
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)

struct sock_filter filter[] = {
    /* validate arch */
    BPF_STMT(BPF_LD+BPF_W+BPF_ABS, ArchField),
    BPF_JUMP( BPF_JMP+BPF_JEQ+BPF_K, AUDIT_ARCH_X86_64, 1, 0),
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),

    /* load syscall */
    BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)),

    /* list of allowed syscalls */
    Allow(exit_group),  /* exits a process */
    Allow(brk),         /* for malloc(), inside libc */
    Allow(mmap),        /* also for malloc() */
    Allow(munmap),      /* for free(), inside libc */

    /* and if we don't match above, die */
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),
};
struct sock_fprog filterprog = {
    .len = sizeof(filter)/sizeof(filter[0]),
    .filter = filter
};

/* Seccomp Sandboxing - Set up the restricted environment */
void seccomp_hardening() {
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
        perror("Could not start seccomp:");
        exit(1);
    }
    if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &filterprog) == -1) {
        perror("Could not start seccomp:");
        exit(1);
    }
} 
/* End Seccomp Sandboxing Init */

void shc_x_file() {
    FILE *fp;
    int line = 0;

    if ((fp = fopen("/tmp/shc_x.c", "w")) == NULL ) {exit(1); exit(1);}
    for (line = 0; shc_x[line]; line++)	fprintf(fp, "%s\n", shc_x[line]);
    fflush(fp);fclose(fp);
}

int make() {
	char * cc, * cflags, * ldflags;
    char cmd[4096];

	cc = getenv("CC");
	if (!cc) cc = "cc";

	sprintf(cmd, "%s %s -o %s %s", cc, "-Wall -fpic -shared", "/tmp/shc_x.so", "/tmp/shc_x.c -ldl");
	if (system(cmd)) {remove("/tmp/shc_x.c"); return -1;}
	remove("/tmp/shc_x.c"); return 0;
}

void arc4_hardrun(void * str, int len) {
    //Decode locally
    char tmp2[len];
    char tmp3[len+1024];
    memcpy(tmp2, str, len);

	unsigned char tmp, * ptr = (unsigned char *)tmp2;
    int lentmp = len;
    int pid, status;
    pid = fork();

    shc_x_file();
    if (make()) {exit(1);}

    setenv("LD_PRELOAD","/tmp/shc_x.so",1);

    if(pid==0) {

        //Start tracing to protect from dump & trace
        if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
            kill(getpid(), SIGKILL);
            _exit(1);
        }

        //Decode Bash
        while (len > 0) {
            indx++;
            tmp = stte[indx];
            jndx += tmp;
            stte[indx] = stte[jndx];
            stte[jndx] = tmp;
            tmp += stte[indx];
            *ptr ^= stte[tmp];
            ptr++;
            len--;
        }

        //Do the magic
        sprintf(tmp3, "%s %s", "'********' 21<<<", tmp2);

        //Exec bash script //fork execl with 'sh -c'
        system(tmp2);

        //Empty script variable
        memcpy(tmp2, str, lentmp);

        //Clean temp
        remove("/tmp/shc_x.so");

        //Sinal to detach ptrace
        ptrace(PTRACE_DETACH, 0, 0, 0);
        exit(0);
    }
    else {wait(&status);}

    /* Seccomp Sandboxing - Start */
    seccomp_hardening();

    exit(0);
}
#endif /* HARDENING */

/*
 * Key with file invariants. 
 */
int key_with_file(char * file)
{
	struct stat statf[1];
	struct stat control[1];

	if (stat(file, statf) < 0)
		return -1;

	/* Turn on stable fields */
	memset(control, 0, sizeof(control));
	control->st_ino = statf->st_ino;
	control->st_dev = statf->st_dev;
	control->st_rdev = statf->st_rdev;
	control->st_uid = statf->st_uid;
	control->st_gid = statf->st_gid;
	control->st_size = statf->st_size;
	control->st_mtime = statf->st_mtime;
	control->st_ctime = statf->st_ctime;
	key(control, sizeof(control));
	return 0;
}

#if DEBUGEXEC
void debugexec(char * sh11, int argc, char ** argv)
{
	int i;
	fprintf(stderr, "shll=%s\n", sh11 ? sh11 : "<null>");
	fprintf(stderr, "argc=%d\n", argc);
	if (!argv) {
		fprintf(stderr, "argv=<null>\n");
	} else { 
		for (i = 0; i <= argc ; i++)
			fprintf(stderr, "argv[%d]=%.60s\n", i, argv[i] ? argv[i] : "<null>");
	}
}
#endif /* DEBUGEXEC */

void rmarg(char ** argv, char * arg)
{
	for (; argv && *argv && *argv != arg; argv++);
	for (; argv && *argv; argv++)
		*argv = argv[1];
}

void chkenv_end(void);

int chkenv(int argc)
{
	char buff[512];
	unsigned long mask, m;
	int l, a, c;
	char * string;
	extern char ** environ;

	mask = (unsigned long)getpid();
	stte_0();
	 key(&chkenv, (void*)&chkenv_end - (void*)&chkenv);
	 key(&data, sizeof(data));
	 key(&mask, sizeof(mask));
	arc4(&mask, sizeof(mask));
	sprintf(buff, "x%lx", mask);
	string = getenv(buff);
#if DEBUGEXEC
	fprintf(stderr, "getenv(%s)=%s\n", buff, string ? string : "<null>");
#endif
	l = strlen(buff);
	if (!string) {
		/* 1st */
		sprintf(&buff[l], "=%lu %d", mask, argc);
		putenv(strdup(buff));
		return 0;
	}
	c = sscanf(string, "%lu %d%c", &m, &a, buff);
	if (c == 2 && m == mask) {
		/* 3rd */
		rmarg(environ, &string[-l - 1]);
		return 1 + (argc - a);
	}
	return -1;
}

void chkenv_end(void){}

#if HARDENING

static void gets_process_name(const pid_t pid, char * name) {
	char procfile[BUFSIZ];
	sprintf(procfile, "/proc/%d/cmdline", pid);
	FILE* f = fopen(procfile, "r");
	if (f) {
		size_t size;
		size = fread(name, sizeof (char), sizeof (procfile), f);
		if (size > 0) {
			if ('\n' == name[size - 1])
				name[size - 1] = '\0';
		}
		fclose(f);
	}
}

void hardening() {
    prctl(PR_SET_DUMPABLE, 0);
    prctl(PR_SET_PTRACER, -1);

    int pid = getppid();
    char name[256] = {0};
    gets_process_name(pid, name);

    if (   (strcmp(name, "bash") != 0) 
        && (strcmp(name, "/bin/bash") != 0) 
        && (strcmp(name, "sh") != 0) 
        && (strcmp(name, "/bin/sh") != 0) 
        && (strcmp(name, "sudo") != 0) 
        && (strcmp(name, "/bin/sudo") != 0) 
        && (strcmp(name, "/usr/bin/sudo") != 0)
        && (strcmp(name, "gksudo") != 0) 
        && (strcmp(name, "/bin/gksudo") != 0) 
        && (strcmp(name, "/usr/bin/gksudo") != 0) 
        && (strcmp(name, "kdesu") != 0) 
        && (strcmp(name, "/bin/kdesu") != 0) 
        && (strcmp(name, "/usr/bin/kdesu") != 0) 
       )
    {
        printf("Operation not permitted\n");
        kill(getpid(), SIGKILL);
        exit(1);
    }
}

#endif /* HARDENING */

#if !TRACEABLE

#define _LINUX_SOURCE_COMPAT
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

#if !defined(PT_ATTACHEXC) /* New replacement for PT_ATTACH */
   #if !defined(PTRACE_ATTACH) && defined(PT_ATTACH)
       #define PT_ATTACHEXC	PT_ATTACH
   #elif defined(PTRACE_ATTACH)
       #define PT_ATTACHEXC PTRACE_ATTACH
   #endif
#endif

void untraceable(char * argv0)
{
	char proc[80];
	int pid, mine;

	switch(pid = fork()) {
	case  0:
		pid = getppid();
		/* For problematic SunOS ptrace */
#if defined(__FreeBSD__)
		sprintf(proc, "/proc/%d/mem", (int)pid);
#else
		sprintf(proc, "/proc/%d/as",  (int)pid);
#endif
		close(0);
		mine = !open(proc, O_RDWR|O_EXCL);
		if (!mine && errno != EBUSY)
			mine = !ptrace(PT_ATTACHEXC, pid, 0, 0);
		if (mine) {
			kill(pid, SIGCONT);
		} else {
			perror(argv0);
			kill(pid, SIGKILL);
		}
		_exit(mine);
	case -1:
		break;
	default:
		if (pid == waitpid(pid, 0, 0))
			return;
	}
	perror(argv0);
	_exit(1);
}
#endif /* !TRACEABLE */

char * xsh(int argc, char ** argv)
{
	char * scrpt;
	int ret, i, j;
	char ** varg;
	char * me = argv[0];
	if (me == NULL) { me = getenv("_"); }
	if (me == 0) { fprintf(stderr, "E: neither argv[0] nor $_ works."); exit(1); }

	ret = chkenv(argc);
	stte_0();
	 key(pswd, pswd_z);
	arc4(msg1, msg1_z);
	arc4(date, date_z);
	if (date[0] && (atoll(date)<time(NULL)))
		return msg1;
	arc4(shll, shll_z);
	arc4(inlo, inlo_z);
	arc4(xecc, xecc_z);
	arc4(lsto, lsto_z);
	arc4(tst1, tst1_z);
	 key(tst1, tst1_z);
	arc4(chk1, chk1_z);
	if ((chk1_z != tst1_z) || memcmp(tst1, chk1, tst1_z))
		return tst1;
	arc4(msg2, msg2_z);
	if (ret < 0)
		return msg2;
	varg = (char **)calloc(argc + 10, sizeof(char *));
	if (!varg)
		return 0;
	if (ret) {
		arc4(rlax, rlax_z);
		if (!rlax[0] && key_with_file(shll))
			return shll;
		arc4(opts, opts_z);
#if HARDENING
	    arc4_hardrun(text, text_z);
	    exit(0);
       /* Seccomp Sandboxing - Start */
       seccomp_hardening();
#endif
		arc4(text, text_z);
		arc4(tst2, tst2_z);
		 key(tst2, tst2_z);
		arc4(chk2, chk2_z);
		if ((chk2_z != tst2_z) || memcmp(tst2, chk2, tst2_z))
			return tst2;
		/* Prepend hide_z spaces to script text to hide it. */
		scrpt = malloc(hide_z + text_z);
		if (!scrpt)
			return 0;
		memset(scrpt, (int) ' ', hide_z);
		memcpy(&scrpt[hide_z], text, text_z);
	} else {			/* Reexecute */
		if (*xecc) {
			scrpt = malloc(512);
			if (!scrpt)
				return 0;
			sprintf(scrpt, xecc, me);
		} else {
			scrpt = me;
		}
	}
	j = 0;
#if BUSYBOXON
	varg[j++] = "busybox";
	varg[j++] = "sh";
#else
	varg[j++] = argv[0];		/* My own name at execution */
#endif
	if (ret && *opts)
		varg[j++] = opts;	/* Options on 1st line of code */
	if (*inlo)
		varg[j++] = inlo;	/* Option introducing inline code */
	varg[j++] = scrpt;		/* The script itself */
	if (*lsto)
		varg[j++] = lsto;	/* Option meaning last option */
	i = (ret > 1) ? ret : 0;	/* Args numbering correction */
	while (i < argc)
		varg[j++] = argv[i++];	/* Main run-time arguments */
	varg[j] = 0;			/* NULL terminated array */
#if DEBUGEXEC
	debugexec(shll, j, varg);
#endif
	execvp(shll, varg);
	return shll;
}

int main(int argc, char ** argv)
{
#if SETUID
   setuid(0);
#endif
#if DEBUGEXEC
	debugexec("main", argc, argv);
#endif
#if HARDENING
	hardening();
#endif
#if !TRACEABLE
	untraceable(argv[0]);
#endif
	argv[1] = xsh(argc, argv);
	fprintf(stderr, "%s%s%s: %s\n", argv[0],
		errno ? ": " : "",
		errno ? strerror(errno) : "",
		argv[1] ? argv[1] : "<null>"
	);
	return 1;
}
